<?php
use yii\db\Schema;  
use yii\db\Migration;  
class admin extends Migration  
{  
    const TBL_NAME = '{{%admin}}';  
    public function safeUp()  
    {  
        $tableOptions = null;  
        if ($this->db->driverName === 'mysql') {  
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci  
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';  
        }  
        $this->createTable(self::TBL_NAME, [  
            'id' => Schema::TYPE_PK,  
            'username' => Schema::TYPE_STRING . ' NOT NULL',  
            'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',    
            'password_hash' => Schema::TYPE_STRING . ' NOT NULL', //密码  
            'password_reset_token' => Schema::TYPE_STRING,  
            'email' => Schema::TYPE_STRING . ' NOT NULL',  
            'role' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10',  
            'status' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 10',  
            'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',  
            'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',  
        ], $tableOptions);  
          
        $this->createIndex('username', self::TBL_NAME, ['username'],true);  
        $this->createIndex('email', self::TBL_NAME, ['email'],true);  
    }  
    public function safeDown()  
    {  
        $this->dropTable(self::TBL_NAME);  
    }  
}  